﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Com.Framework;
using Com.Framework.Data;
using Com.Library.DB.UserCard;
using Com.Web.coffinegurunaru.AppLogic.Page;

namespace Com.Web.coffinegurunaru.mypage
{
	public partial class card_enroll : WebPage
	{
		public List<UserCardEntity> CardList
		{
			get;
			set;
		}

		public int PageNo
		{
			get;
			set;
		}

		public byte PageSize
		{
			get
			{
				return 10;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			this.LeftMenuType = 2;
			this.PageNo = Request.QueryString["PageNo"].Parse(1);

			if (this.IsPostBack)
			{
				string CardNo1 = Request.Form["CardNo1"].Parse(string.Empty);
				string Card = CardNo1;

				UserCardEntity info = UserCardModel.GetInfo(Card);
				if (info.UserCardNo != 0)
				{
					Response.Clear();
					Response.Write("<script language='javascript'>alert('이미 등록된 카드입니다.'); location.href='/mypage/card_enroll.aspx?PageNo=" + this.PageNo.ToString() + "';</script>");
					Response.End();
				}

				if (CardNo1.Length < 6)
				{
					Response.Clear();
					Response.Write("<script language='javascript'>alert('카드 번호가 잘못되었습니다.'); location.href='/mypage/card_enroll.aspx?PageNo=" + this.PageNo.ToString() + "';</script>");
					Response.End();
				}

				UserCardModel.Create(this.WebCookies.UserNo, Card);
			}

			ListData<UserCardEntity, OutputEntity> result = UserCardModel.GetList(this.WebCookies.UserNo, CodeCardStatus.Create, PageNo, PageSize);
			CardList = result.Record;
			UC_Paging.TotalCount = result.Output.CntTotal;
			UC_Paging.PageName = "PageNo";
			UC_Paging.PageNo = PageNo;
			UC_Paging.PageSize = PageSize;
		}
	}
}
